﻿using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using OptoMeasure.Views;
using System.Windows.Media.Imaging;
using Om.Core.Singleton;
using System.Windows;
using CommunityToolkit.Mvvm.Messaging;
using OptoMeasure.Extension;

namespace OptoMeasure;

public partial class MainViewModel : ObservableRecipient
{
    public ObservableCollection<CameraViewModel> CameraVmList { get; set; } = new();

    public Visibility PtzVisibility => DevicesConfig.Instance.NeedPtz == 0 ? Visibility.Collapsed : Visibility.Visible;

    public MainViewModel()
    {
        WeakReferenceMessenger.Default.Register<object,string>(this, MsgToken.CameraConnectedChanged, (recipient, message) =>
        {
            var cameras = DevicesManager.Instance.GetBaseCameras();
            CameraVmList.Clear();
            foreach (var item in cameras.Where(a => a.Value.IsConnected))
            {
                var cameraName = item.Key;
                var camera = item.Value;
                var itemVm = new CameraViewModel(cameraName, camera);
                CameraVmList.Add(itemVm);
            }
        });

    }

}